<template>
  <div>
    <el-table v-loading="loading" :data="noticeList">
      <el-table-column label="序号" align="center" prop="order" width="50" />
      <!-- <el-table-column label="图片" align="center" min-width="120">
        <template slot-scope="scope">
          <el-image fit="cover" style="width:100px;height:100px" :src="scope.row.image"></el-image>
        </template>
      </el-table-column> -->
      <el-table-column label="计划编号" align="center" min-width="150">
        <template slot-scope="scope">
          <el-link @click="handledetailed(scope.row)" type="primary">{{ scope.row.planNum || '-' }}</el-link>
        </template>
      </el-table-column>
      <el-table-column label="任务编号" align="center" min-width="150">
        <template slot-scope="scope">
          <el-link @click="handledetailed(scope.row)" type="primary">{{ scope.row.taskNum || '-' }}</el-link>
        </template>
      </el-table-column>
      <el-table-column label="盘点范围" align="center" min-width="150" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ scope.row.stktakingDeptName || '-' }}
        </template>
      </el-table-column>
      <el-table-column label="责任部门" align="center" min-width="150" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ scope.row.deptName || '-' }}
        </template>
      </el-table-column>
      <el-table-column label="主要负责人" align="center" min-width="120">
        <template slot-scope="scope">
          {{ scope.row.headName || '-' }}
        </template>
      </el-table-column>
      <el-table-column label="盘点方式" align="center" min-width="120">
        <template slot-scope="scope">
          {{ ['全盘盘点', '比例盘点'][scope.row.type] || '-' }}
        </template>
      </el-table-column>
      <el-table-column label="盘点比例" align="center" min-width="120">
        <template slot-scope="scope">
          {{ scope.row.type === '0' ? '-' : scope.row.proportion * 100 + '%' || '0%' }}

        </template>
      </el-table-column>
      <el-table-column label="盘点对象生成方式" align="center" min-width="150">
        <template slot-scope="scope">
          {{ ['随机生成', '手动生成'][scope.row.generationType] || '-' }}
          <!-- <dict-tag :options="statusAllocation" :value="scope.row.status" /> -->
        </template>
      </el-table-column>
      <el-table-column label="开始盘点时间" align="center" min-width="160">
        <template slot-scope="scope">
          {{ scope.row.startTime || '-' }}
        </template>
      </el-table-column>
      <el-table-column label="平账时间" align="center" min-width="160">
        <template slot-scope="scope">
          {{ scope.row.accountTime || '-' }}
        </template>
      </el-table-column>
      <el-table-column label="任务状态" align="center" min-width="130">
        <template slot-scope="scope">
          <dict-tag :options="statusPlan" :value="scope.row.status" />
        </template>
      </el-table-column>
      <el-table-column label="应盘" align="center" min-width="100">
        <template slot-scope="scope">
          {{ scope.row.planCount || '0' }}
        </template>
      </el-table-column>
      <el-table-column label="已盘" align="center" min-width="100">
        <template slot-scope="scope">
          {{ scope.row.completeCount || '0' }}
        </template>
      </el-table-column>
      <el-table-column label="平账" align="center" min-width="100">
        <template slot-scope="scope">
          <div :style="'color:' + ['#67C23A', '#F56C6C'][scope.row.accountFlag]">
            <!-- <i :class="['el-icon-success', 'el-icon-remove'][scope.row.status]" />
            <span>
              {{ ['启用中', '禁用中'][scope.row.status] }}
            </span> -->
            {{ ['已平账', '未平帐'][scope.row.accountFlag] || '0' }}
          </div>


        </template>
      </el-table-column>
      <el-table-column label="创建部门" align="center" min-width="180" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ scope.row.deptName || '-' }}
        </template>
      </el-table-column>
      <el-table-column label="创建人" align="center" min-width="120" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ scope.row.createBy || '-' }}
        </template>
      </el-table-column>
      <!-- <el-table-column label="操作" width="300" fixed="right" align="center">
        <template slot-scope="scope" v-if="scope.row.taskGenFlag === '1'">
          <el-button size="small" type="primary" icon="el-icon-edit" @click="handleUpdate(scope.row)">编辑</el-button>
          <el-button size="small" type="danger" icon="el-icon-delete" @click="handleDelete(scope.row)">删除</el-button>
          <el-button size="small" type="warning" icon="el-icon-plus" @click="handleSelect(scope.row)">生成任务
          </el-button>
        </template>
      </el-table-column> -->
    </el-table>
    <div class="card-div">
      <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
        @pagination="getList" />
    </div>
    <!-- 查看审核流程 -->
    <!-- <template v-if="opendetailed">
      <ReconsiDeration :rowObj="detailedObj"></ReconsiDeration>
    </template> -->
  </div>
</template>

<script>
import { getTaskGenList, DeleteStktaking, putTaskGen } from "@/api/Inventory/Inventory.js";
export default {
  // dicts: ['sys_notice_status', 'sys_notice_type'],
  components: {
    // ReconsiDeration: () => import('../form/reconsideration.vue')//审核流程
  },
  data () {
    return {
      // 遮罩层
      loading: true,
      opendetailed: false,
      detailedObj: {},
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      dictdatalist: [],
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 弹出层表格数据
      noticeList: [],
      rowObj: {},
      // 弹出层标题
      title: "修改",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderByColumn: 'taskId',
        isAsc: 'desc'//倒叙
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        noticeTitle: [
          { required: true, message: "公告标题不能为空", trigger: "blur" }
        ],
        noticeType: [
          { required: true, message: "公告类型不能为空", trigger: "change" }
        ]
      }
    };
  },
  created () {
    this.getList();
  },
  methods: {
    /** 查询列表 */
    async getList (value) {
      this.loading = true;
      let obj = value || {}
      let params = {
        ...this.queryParams,
        ...obj
      }
      getTaskGenList(params).then(response => {
        this.noticeList = response.data && response.data.map((item, index) => {
          return {
            ...item,
            order: index + 1
          }
        });
        this.total = response.total;
        this.loading = false;
      });
    },
    // 打开详细弹窗
    handledetailed (row) {
      this.$emit('handleOpen', row)
      // this.$parent.$parent.$parent.$parent.tabIndex = true
      // this.$parent.$parent.$parent.$parent.activeName = '3'
      // this.$parent.$parent.$parent.$parent.rowObj = row
    },
    /** 生成按钮操作 */
    handleSelect (row) {
      this.$confirm(`是否确认生成盘点任务`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.loading = true;
        let params = row.planId
        putTaskGen(params).then(res => {
          if (res.code === 200) {
            this.$message.success(res.msg)
            this.getList()
          }
          this.loading = false;
        }).catch(() => { this.loading = false; });
      }).catch(() => { })
    },
    handleUpdate (row) {//编辑
      this.$emit('handleUpdate', row.planId)
    },
    // 多选框选中数据
    handleSelectionChange (selection) {
      this.ids = selection.map(item => item.noticeId)
      this.single = selection.length != 1
      this.multiple = !selection.length
    },
    /** 启用禁用按钮操作 */
    handleDelete (row) {
      this.$confirm(`是否确认删除该数据`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.loading = true;
        let params = row.planId
        DeleteStktaking(params).then(res => {
          if (res.code === 200) {
            this.$message.success(res.msg)
            this.getList()
          }
          this.loading = false;
        }).catch(() => { this.loading = false; });
      }).catch(() => { })
    }
  },
  filters: {
  }
};
</script>
<style lang="scss" scoped>
.red {
  color: red;
}
</style>